﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace BACKOFFICE
{
    public partial class Scheduler : DevExpress.XtraEditors.XtraUserControl
    {
        
        Dictionary<int, List<Control>> EmployeeBoxes = new Dictionary<int, List<Control>>(); // Employee ID , Time Boxes

        public Scheduler()
        {
            InitializeComponent();

            //DataTableClass.SQLServerIP = "192.168.1.13";
            //DataTableClass.SQLServerPORT = "51274";
            //DataTableClass.myConnectionString = DataTableClass.connectionstring();

            //DataTableClass.LoadDataTable("EmployeeLogin",DataTableClass.EmployeeLogin);

            foreach (DataRow JobTitle in DataTableClass.EmployeeLogin.Rows)
            {
                if (!cmbEmployeeGroup.Properties.Items.Contains(JobTitle["EmployeeTitle"].ToString().Trim()))
                {
                    cmbEmployeeGroup.Properties.Items.Add(JobTitle["EmployeeTitle"].ToString().Trim());
                }
            }
        }

        private void simpleButton4_Click(object sender, EventArgs e)
        {
            int EmployeeNameXlocation = 14;
            int EmployeeNameYlocation = 150;

            int TimeBoxXStartLocation = 128;
            int TimeBoxYStartLocation = 120;

            int ScreenSize = 0;
            int i = 0;

            btnStart.Visible = false;
            btnSave.Visible = true;
            btnPrint.Visible = true;
            btnCancel.Visible = true;

            foreach(DataRow Employee in DataTableClass.EmployeeLogin.Rows)
            {
                if (Employee["EmployeeTitle"].ToString().Trim() == cmbEmployeeGroup.SelectedText)
                {
                    LabelControl EmployeeName = new LabelControl();
                    EmployeeName.Text = Employee["EmployeeFullName"].ToString().Trim();
                    EmployeeName.Location = new Point(EmployeeNameXlocation, TimeBoxYStartLocation);
                    EmployeeName.Name = "lblEmployeeID" + Employee["EmployeeID"].ToString().Trim();


                    ComboBoxEdit TimeBox1 = new ComboBoxEdit();
                    TimeBox1.Name = (i++).ToString();
                    TimeBox1.Location = new Point(TimeBoxXStartLocation, TimeBoxYStartLocation);
                    FillComboBox(TimeBox1);
                    this.Controls.Add(TimeBox1);
                   
                    TimeBoxXStartLocation += 105;
                    ComboBoxEdit TimeBox2 = new ComboBoxEdit();
                    TimeBox2.Name = (i++).ToString();
                    TimeBox2.Location = new Point(TimeBoxXStartLocation , TimeBoxYStartLocation);
                    FillComboBox(TimeBox2);
                    this.Controls.Add(TimeBox2);
                    lblMondayHeader.Location = new Point(TimeBox2.Location.X - 25, 122);
                    lblDate1.Location = new Point(TimeBox2.Location.X - 25, 146);

                    TimeBoxXStartLocation += 110;
                    ComboBoxEdit TimeBox3 = new ComboBoxEdit();
                    TimeBox3.Name = (i++).ToString();
                    TimeBox3.Location = new Point(TimeBoxXStartLocation, TimeBoxYStartLocation);
                    FillComboBox(TimeBox3);
                    this.Controls.Add(TimeBox3);

                    TimeBoxXStartLocation += 105;
                    ComboBoxEdit TimeBox4 = new ComboBoxEdit();
                    TimeBox4.Name = (i++).ToString();
                    TimeBox4.Location = new Point(TimeBoxXStartLocation, TimeBoxYStartLocation);
                    FillComboBox(TimeBox4);
                    this.Controls.Add(TimeBox4);
                    lblTuesdayHeader.Location = new Point(TimeBox4.Location.X - 27, 122);
                    lblDate2.Location = new Point(TimeBox4.Location.X - 27, 146);

                    TimeBoxXStartLocation += 110;
                    ComboBoxEdit TimeBox5 = new ComboBoxEdit();
                    TimeBox5.Name = (i++).ToString();
                    TimeBox5.Location = new Point(TimeBoxXStartLocation, TimeBoxYStartLocation);
                    FillComboBox(TimeBox5);
                    this.Controls.Add(TimeBox5);

                    TimeBoxXStartLocation += 105;
                    ComboBoxEdit TimeBox6 = new ComboBoxEdit();
                    TimeBox6.Name = (i++).ToString();
                    TimeBox6.Location = new Point(TimeBoxXStartLocation, TimeBoxYStartLocation);
                    FillComboBox(TimeBox6);
                    this.Controls.Add(TimeBox6);
                    lblWednesdayHeader.Location = new Point(TimeBox6.Location.X - 38, 122);
                    lblDate3.Location = new Point(TimeBox6.Location.X - 38, 146);

                    TimeBoxXStartLocation += 110;
                    ComboBoxEdit TimeBox7 = new ComboBoxEdit();
                    TimeBox7.Name = (i++).ToString();
                    TimeBox7.Location = new Point(TimeBoxXStartLocation, TimeBoxYStartLocation);
                    FillComboBox(TimeBox7);
                    this.Controls.Add(TimeBox7);

                    TimeBoxXStartLocation += 105;
                    ComboBoxEdit TimeBox8 = new ComboBoxEdit();
                    TimeBox8.Name = (i++).ToString();
                    TimeBox8.Location = new Point(TimeBoxXStartLocation, TimeBoxYStartLocation);
                    FillComboBox(TimeBox8);
                    this.Controls.Add(TimeBox8);
                    lblThursdayHeader.Location = new Point(TimeBox8.Location.X - 30, 122);
                    lblDate4.Location = new Point(TimeBox8.Location.X - 30, 146);

                    TimeBoxXStartLocation += 110;
                    ComboBoxEdit TimeBox9 = new ComboBoxEdit();
                    TimeBox9.Name = (i++).ToString();
                    TimeBox9.Location = new Point(TimeBoxXStartLocation, TimeBoxYStartLocation);
                    FillComboBox(TimeBox9);
                    this.Controls.Add(TimeBox9);

                    TimeBoxXStartLocation += 105;
                    ComboBoxEdit TimeBox10 = new ComboBoxEdit();
                    TimeBox10.Name = (i++).ToString();
                    TimeBox10.Location = new Point(TimeBoxXStartLocation, TimeBoxYStartLocation);
                    FillComboBox(TimeBox10);
                    this.Controls.Add(TimeBox10);
                    lblFridayHeader.Location = new Point(TimeBox10.Location.X - 19, 122);
                    lblDate5.Location = new Point(TimeBox10.Location.X - 19, 146);

                    TimeBoxXStartLocation += 110;
                    ComboBoxEdit TimeBox11 = new ComboBoxEdit();
                    TimeBox11.Name = (i++).ToString();
                    TimeBox11.Location = new Point(TimeBoxXStartLocation, TimeBoxYStartLocation);
                    FillComboBox(TimeBox11);
                    this.Controls.Add(TimeBox11);

                    TimeBoxXStartLocation += 105;
                    ComboBoxEdit TimeBox12 = new ComboBoxEdit();
                    TimeBox12.Name = (i++).ToString();
                    TimeBox12.Location = new Point(TimeBoxXStartLocation, TimeBoxYStartLocation);
                    FillComboBox(TimeBox12);
                    this.Controls.Add(TimeBox12);
                    lblSaturdayHeader.Location = new Point(TimeBox12.Location.X - 30, 122);
                    lblDate6.Location = new Point(TimeBox12.Location.X - 30, 146);

                    TimeBoxXStartLocation += 110;
                    ComboBoxEdit TimeBox13 = new ComboBoxEdit();
                    TimeBox13.Name = (i++).ToString();
                    TimeBox13.Location = new Point(TimeBoxXStartLocation, TimeBoxYStartLocation);
                    FillComboBox(TimeBox13);
                    this.Controls.Add(TimeBox13);

                    TimeBoxXStartLocation += 105;
                    ComboBoxEdit TimeBox14 = new ComboBoxEdit();
                    TimeBox14.Name = (i++).ToString();
                    TimeBox14.Location = new Point(TimeBoxXStartLocation, TimeBoxYStartLocation);
                    FillComboBox(TimeBox14);
                    this.Controls.Add(TimeBox14);
                    lblSundayHeader.Location = new Point(TimeBox14.Location.X - 24, 122);
                    lblDate7.Location = new Point(TimeBox14.Location.X - 24, 146);
                    ScreenSize = TimeBoxXStartLocation;



                    this.Controls.Add(EmployeeName);
                    EmployeeBoxes.Add(Convert.ToInt32(Employee["EmployeeID"].ToString().Trim()), new List<Control>
                        {
                            TimeBox1,
                            TimeBox2,
                            TimeBox3,
                            TimeBox4,
                            TimeBox5,
                            TimeBox6,
                            TimeBox7,
                            TimeBox8,
                            TimeBox9,
                            TimeBox10,
                            TimeBox11,
                            TimeBox12,
                            TimeBox13,
                            TimeBox14,
                        
                        });



                }
                TimeBoxXStartLocation = 128;
                TimeBoxYStartLocation += 30;

                EmployeeNameYlocation += 60;

            }

            this.Size = new System.Drawing.Size(ScreenSize + 150,this.Size.Height);
            lblDate1.Visible = true;
            lblDate2.Visible = true;
            lblDate3.Visible = true;
            lblDate4.Visible = true;
            lblDate5.Visible = true;
            lblDate6.Visible = true;
            lblDate7.Visible = true;

            lblMondayHeader.Visible = true;
            lblTuesdayHeader.Visible = true;
            lblWednesdayHeader.Visible = true;
            lblThursdayHeader.Visible = true;
            lblFridayHeader.Visible = true;
            lblSaturdayHeader.Visible = true;
            lblSundayHeader.Visible = true;
        }
        
        private void FillComboBox(object sender)
        {
            var items = (ComboBoxEdit)sender;

            items.Properties.Items.Add("10:30 AM");
            items.Properties.Items.Add("11:00 AM");
            items.Properties.Items.Add("11:30 AM");
            items.Properties.Items.Add("12:00 PM");
            items.Properties.Items.Add("12:30 PM");
            items.Properties.Items.Add("1:00 PM");
            items.Properties.Items.Add("1:30 PM");
            items.Properties.Items.Add("2:00 PM");
            items.Properties.Items.Add("2:30 PM");
            items.Properties.Items.Add("3:00 PM");
            items.Properties.Items.Add("3:30 PM");
            items.Properties.Items.Add("4:00 PM");
            items.Properties.Items.Add("4:30 PM");
            items.Properties.Items.Add("5:00 PM");
            items.Properties.Items.Add("5:30 PM");
            items.Properties.Items.Add("6:00 PM");
            items.Properties.Items.Add("6:30 PM");
            items.Properties.Items.Add("7:00 PM");
            items.Properties.Items.Add("7:30 PM");
            items.Properties.Items.Add("8:00 PM");
            items.Properties.Items.Add("8:30 PM");
            items.Properties.Items.Add("9:00 PM");
            items.Properties.Items.Add("9:30 PM");
            items.Properties.Items.Add("10:00 PM");
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            foreach(KeyValuePair<int,List<Control>> item in EmployeeBoxes)
            {
                MessageBox.Show(item.Value[13].Text);
            }
        }
    }
}
